---
<!-- Copyright © SixtyFPS GmbH <info@slint.dev> ; SPDX-License-Identifier: MIT -->
title: Name Resolution (Scope)
description: Name Resolution (Scope)
---

Function calls have the same name resolution rules as properties and callbacks. When called without
an element name:

- If the element that the function is called in (`self`) defines a function with that name, it is chosen.
- If not, name resolution continues to its parent element, and so on, until the root component.

When called with an element name (or `self`, `parent` or `root`), the function must be defined on that
element. Name resolution does not look at ancestor elements in this case. Note that this means
calling a function without an element name is _not_ equivalent to calling it with `self` (which is how methods work in many languages).

Multiple functions with the same name are allowed in the same component, as long as they are defined
on different elements. Therefore it is possible for a function to shadow another function from an ancestor
element.

```slint
export component Example {
    property <int> secret_number: my-function();
    public pure function my-function() -> int {
        return 1;
    }

    VerticalLayout {
        public pure function my-function() -> int {
            return 2;
        }

        Text {
            text: "The secret number is " + my-function();
            public pure function my-function() -> int {
                return 3;
            }
        }

        Text {
            text: "The other secret number is " + my-function();
        }
    }
}
```

In the example above, the property `secret_number` will be set to 1, and the text labels will say "The
secret number is 3" and "The other secret number is 2".
